/**
 * 基类
 */

import Vue from "vue";
import { SubmitButton, RefreshButton } from "@/components/aws-comp";

Vue.component(SubmitButton.name, SubmitButton);
Vue.component(RefreshButton.name, RefreshButton);

import dayjs from "dayjs";

export default {
  data() {},
  methods: {
    /**显示新建数据成功 */
    showNewSuccess(msg) {
      this.$message({ type: "success", message: msg || "新建成功" });
    },
    /**显示编辑数据成功 */
    showUpdateSuccess(msg) {
      this.$message({ type: "success", message: msg || "编辑保存成功" });
    },

    /**显示是否确定删除 */
    isDeleteConfirm(msg) {
      var options = {
        confirmButtonText: "确定删除",
        cancelButtonText: "取消",
        type: "warning"
      };

      return this.$confirm(
        msg || "此操作将永久删除选定的数据, 是否继续?",
        "提示",
        options
      );
    },

    /**
     * 操作成功信息
     * @param {*} msg
     */
    showSuccess(msg) {
      this.$message({ type: "success", message: msg || "操作成功" });
    },

    getServerUrl(url) {
      if (!url) return url;
      if (url.toUpperCase().indexOf("http://") !== -1) return url; // 写死的不做处理
      if (url.toUpperCase().indexOf("https://") !== -1) return url;
      var prefix = process.env.NODE_ENV == "development" ? "/api/" : "/";
      url = prefix + url;
      url = url.replace("//", "/");
      return url;
    },
    nextMethod() {}
  },
  filters: {
    format(val, format) {
      if (!val) return val;
      return dayjs(val).format(format);
    }
  }
};
